package com.bbs.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bbs.model.User;
import com.bbs.server.UserService;

@Controller
@RequestMapping("/user")
public class UserController {
//	BBS-Server-APP
	@Resource
	private UserService userService;

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	@ResponseBody
	public String add(User user) {
		userService.add(user);
		return "success";
	}

	@RequestMapping(value = "/update", method = RequestMethod.GET)
	@ResponseBody
	public String update(User user) {
		userService.update(user);
		return "success";
	}

	@RequestMapping(value = "/delete", method = RequestMethod.GET)
	@ResponseBody
	public String delete(User user) {
		userService.delete(user);
		return "success";
	}

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@ResponseBody
	public List<User> getUserList() {
		List<User> users = userService.getUserList();
		return users;
	}
	
	@RequestMapping(value="/fenye",method=RequestMethod.GET)
	@ResponseBody
	public List<User> fenye(int pageIndex, int pageSize){
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("pageIndex", (pageIndex-1)*pageSize);
        data.put("pageSize", pageSize);
		List<User> fenye = userService.fenye(data);
		return fenye; 
	}
	
	@RequestMapping(value="/chazhao",method=RequestMethod.GET)
	@ResponseBody
	public List<User> chazhao(String keyword){
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("pageIndex",keyword);
		List<User> fenye = userService.chazhao(data);
		return fenye; 
	}
}
